<?php
try{
	include '../ini.php';
    if(isset($_GET['id'])){
        $read=$dt_xl_admin->read_id($_GET['id']);
        if($read === false ){
            throw new Exception('Không tồn tại mã này!!!');
        }
        if($_GET['id'] != $read['id']){
            $_GET['id']=$dt_xl_admin->removeSQLI($_GET['id']);
            header('Location: decentralization.php?id='.$_GET['id']);
        }
    }else{
        $_GET['id']='';
    }
    $dir='..';
    $read_folder=$dt_xl_admin->dirToArray($dir);
    $read_admin=$dt_xl_admin->read();
    $decentralization=$dt_xl_admin->read_id($_GET['id']);
    $save_decentralization=$dt_xl_admin->save_decentralization($_GET['id']);
    $dt_smarty->assign('decentralization',$decentralization);
    $dt_smarty->assign('read_folder',$read_folder);
    $dt_smarty->assign('read_admin',$read_admin);
    $dt_smarty->assign('save_decentralization',$save_decentralization);
	$contenForLayout=$dt_smarty->fetch('board/decentralization.tpl');
	$dt_smarty->assign('contenForLayout',$contenForLayout);
	$dt_smarty->assign('titleForLayout','Phân Quyền');
	$dt_smarty->display('layout/defaults.tpl');
    $dbh=NULL;
} catch(Exception $e){
	$_SESSION['msg']=$e->getMessage();
    $_SESSION['type_msg']='error';
    if(empty($_SERVER['HTTP_REFERER'])){
        header('Location: decentralization.php');
    }else{
        header('Location:'.$_SERVER['HTTP_REFERER']);
    }
	$dbh=NULL;
}